package com.ruoyi.web.controller.business;

import cn.hutool.core.util.RandomUtil;
import com.ruoyi.business.domain.TIsvInfo;
import com.ruoyi.business.service.ITIsvInfoService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 支付宝服务商信息Controller
 * 
 * @author ruoyi
 * @date 2024-03-18
 */
@Controller
@RequestMapping("/business/isvInfo")
public class TIsvInfoController extends BaseController
{
    private String prefix = "business/isvInfo";

    @Autowired
    private ITIsvInfoService tIsvInfoService;

    @RequiresPermissions("business:isvInfo:view")
    @GetMapping()
    public String isvInfo()
    {
        return prefix + "/isvInfo";
    }

    /**
     * 查询支付宝服务商信息列表
     */
    @RequiresPermissions("business:isvInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TIsvInfo tIsvInfo)
    {
        startPage();
        List<TIsvInfo> list = tIsvInfoService.selectTIsvInfoList(tIsvInfo);
        return getDataTable(list);
    }

    /**
     * 导出支付宝服务商信息列表
     */
    @RequiresPermissions("business:isvInfo:export")
    @Log(title = "支付宝服务商信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TIsvInfo tIsvInfo)
    {
        List<TIsvInfo> list = tIsvInfoService.selectTIsvInfoList(tIsvInfo);
        ExcelUtil<TIsvInfo> util = new ExcelUtil<TIsvInfo>(TIsvInfo.class);
        return util.exportExcel(list, "支付宝服务商信息数据");
    }

    /**
     * 新增支付宝服务商信息
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("fileid", RandomUtil.randomString(10));
        return prefix + "/add";
    }

    /**
     * 新增保存支付宝服务商信息
     */
    @RequiresPermissions("business:isvInfo:add")
    @Log(title = "支付宝服务商信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TIsvInfo tIsvInfo)
    {
        return toAjax(tIsvInfoService.insertTIsvInfo(tIsvInfo));
    }

    /**
     * 修改支付宝服务商信息
     */
    @RequiresPermissions("business:isvInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TIsvInfo tIsvInfo = tIsvInfoService.selectTIsvInfoById(id);
        mmap.put("tIsvInfo", tIsvInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存支付宝服务商信息
     */
    @RequiresPermissions("business:isvInfo:edit")
    @Log(title = "支付宝服务商信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TIsvInfo tIsvInfo)
    {
        return toAjax(tIsvInfoService.updateTIsvInfo(tIsvInfo));
    }

    /**
     * 删除支付宝服务商信息
     */
    @RequiresPermissions("business:isvInfo:remove")
    @Log(title = "支付宝服务商信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tIsvInfoService.deleteTIsvInfoByIds(ids));
    }

    /**
     * 用户状态修改
     */
    @Log(title = "nginx服务器", businessType = BusinessType.UPDATE)
    @RequiresPermissions("business:isvInfo:edit")
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(TIsvInfo tIsvInfo) {
        TIsvInfo newTisvInfo = tIsvInfoService.selectTIsvInfoById(tIsvInfo.getId());
        newTisvInfo.setStatus(tIsvInfo.getStatus());
        return toAjax(tIsvInfoService.updateTIsvInfo(newTisvInfo));
//        return toAjax(tNginxInfoService.updateTNginxInfo(tNginxInfo));
    }


}
